﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cvk.FAQs;

namespace BatDongSan.Modules
{
    public partial class Uc_FQA : System.Web.UI.UserControl
    {
        int _idFAQCategory;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                _idFAQCategory = Convert.ToInt32(Request.QueryString["id"]);
                if (_idFAQCategory > 0)
                {
                    lbTitle.Text = "HỎI - ĐÁP / " + FAQBll.claFAQCategory.GetNameById(Utility.strConnect, _idFAQCategory).ToUpper();
                }
                if (!IsPostBack)
                {
                    LoadData();
                }
            }
            catch { }
        }

        protected void LoadData()
        {
            if (_idFAQCategory > 0)
            {
                rptFQA.DataSource = FAQBll.claFAQs.GetFQAByCategoryId(_idFAQCategory, true, Utility.strConnect);
                rptFQA.DataBind();
                if (rptFQA.Items.Count > 0)
                {
                    pnEmptyData.Visible = false;

                }
                else
                {
                    pnEmptyData.Visible = true;
                }
            }
            else
            {
                rptFQA.DataSource = FAQBll.claFAQs.GetList(10, true, Utility.strConnect);
                rptFQA.DataBind();
                if (rptFQA.Items.Count > 0)
                {
                    pnEmptyData.Visible = false;

                }
                else
                {
                    pnEmptyData.Visible = true;
                }
            }
        }
        protected void rptFQA_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            try
            {
                if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                {
                    Cvk_FQA Info = (Cvk_FQA)e.Item.DataItem;
                    Label lbName = (Label)e.Item.FindControl("lbName");
                    lbName.Text = "Người gửi: <b>" + Info.Name + "</b>";

                    Label lbDateCreate = (Label)e.Item.FindControl("lbDateCreate");
                    lbDateCreate.Text = "Ngày gủi: " + string.Format("{0:dd/MM/yyyy}", Info.CreateDate);

                    //Literal ltrContent = (Literal)e.Item.FindControl("ltrContent");
                    //ltrContent.Text = Info.Question;

                    Label lbView = (Label)e.Item.FindControl("lbView");
                    lbView.Text = "Lần xem: " + Info.View.ToString();

                    Label lbReply = (Label)e.Item.FindControl("lbReply");
                    lbReply.Text = "Trả lời: " + FAQBll.claReply.GetListCount(Info.FQAId, true, Utility.strConnect).ToString();

                    HyperLink hplQuention = (HyperLink)e.Item.FindControl("hplQuention");
                    hplQuention.NavigateUrl = "/FQADetail.aspx?id=" + Info.FQAId.ToString();

                    Literal ltrQuestion = (Literal)e.Item.FindControl("ltrQuestion");
                    ltrQuestion.Text =cvk.AppCode.WebUtility.CatString( Utility.RemoveHtml(Info.Question),30);
                }
            }
            catch { }
        }
    }
}